# Copyright (c) 2014 Thomas Heller
# Copyright (c) 2015 Andreas Schaefer
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

set(HPX_FIND_PACKAGE ON)
cmake_policy(VERSION 3.13)

# Forward HPX_* cache variables
include("${CMAKE_CURRENT_LIST_DIR}/HPXCacheVariables.cmake")

# include exported targets
include("${CMAKE_CURRENT_LIST_DIR}/HPXInternalTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/HPXTargets.cmake")

# include HPX cmake utilities
include("${CMAKE_CURRENT_LIST_DIR}/HPXMacros.cmake")

get_filename_component(_hpx_root_dir "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)

set(HPX_VERSION_STRING "@HPX_VERSION@")
set(HPX_VERSION_MAJOR @HPX_VERSION_MAJOR@)
set(HPX_VERSION_MINOR @HPX_VERSION_MINOR@)
set(HPX_VERSION_SUBMINOR @HPX_VERSION_SUBMINOR@)

set(HPX_PREFIX "${_hpx_root_dir}")
set(HPX_DEBUG_POSTFIX "@HPX_DEBUG_POSTFIX@")
set(HPX_BUILD_TYPE "@CMAKE_BUILD_TYPE@")
set(HPX_CXX_STANDARD "@HPX_CXX_STANDARD@")

set(HPX_GIT_COMMIT "@HPX_WITH_GIT_COMMIT@" CACHE STRING "Revision of HPX from Git" FORCE)

set(HPX_C_COMPILER "@CMAKE_C_COMPILER@" CACHE STRING "C compiler for HPX" FORCE)
set(HPX_C_COMPILER_ID "@CMAKE_C_COMPILER_ID@" CACHE STRING "C compiler id for HPX" FORCE)
set(HPX_C_COMPILER_VERSION "@CMAKE_C_COMPILER_VERSION@" CACHE STRING "C compiler version for HPX" FORCE)

set(HPX_CXX_COMPILER "@CMAKE_CXX_COMPILER@" CACHE STRING "CXX compiler for HPX" FORCE)
set(HPX_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@" CACHE STRING "CXX compiler id for HPX" FORCE)
set(HPX_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@" CACHE STRING "CXX compiler version for HPX" FORCE)

set(HPX_Fortran_COMPILER "@CMAKE_Fortran_COMPILER@" CACHE STRING "Fortran compiler for HPX" FORCE)
set(HPX_Fortran_COMPILER_ID "@CMAKE_Fortran_COMPILER_ID@" CACHE STRING "Fortran compiler id for HPX" FORCE)
set(HPX_Fortran_COMPILER_VERSION "@CMAKE_Fortran_COMPILER_VERSION@" CACHE STRING "Fortran compiler version for HPX" FORCE)

##################################################
# Setup the imported libraries (publicly linked) #

# Allocator
set(HPX_JEMALLOC_ROOT "@JEMALLOC_ROOT@")
set(HPX_TCMALLOC_ROOT "@TCMALLOC_ROOT@")
set(HPX_TBBMALLOC_ROOT "@TBBMALLOC_ROOT@")
# Special handle for mimalloc cause we can't specify HPX_MIMALLOC_ROOT as a HINT
# to find_package
set(HPX_MIMALLOC_ROOT "@MIMALLOC_ROOT@")
if (NOT MIMALLOC_ROOT AND NOT "$ENV{MIMALLOC_ROOT}")
  set(MIMALLOC_ROOT ${HPX_MIMALLOC_ROOT})
endif()
include(HPX_SetupAllocator)

# Boost
# Separate boost targets to be unarily linked to some modules
set(HPX_BOOST_ROOT "@BOOST_ROOT@")
# By default BOOST_ROOT is set to HPX_BOOST_ROOT (not necessary for PAPI or
# HWLOC cause we are specifying HPX_<lib>_ROOT as an HINT to find_package)
if (NOT BOOST_ROOT AND NOT "$ENV{BOOST_ROOT}")
  set(BOOST_ROOT ${HPX_BOOST_ROOT})
endif()
include(HPX_SetupBoost)
include(HPX_SetupBoostFilesystem)
include(HPX_SetupBoostProgramOptions)

# Hwloc
set(HPX_HWLOC_ROOT "@HWLOC_ROOT@")
include(HPX_SetupHwloc)

# Papi
set(HPX_PAPI_ROOT "@PAPI_ROOT@")
include(HPX_SetupPapi)

# CUDA
include(HPX_SetupCUDA)

# APEX
set(APEX_WITH_MSR "@APEX_WITH_MSR@")
set(MSR_ROOT "@MSR_ROOT@")
set(APEX_WITH_ACTIVEHARMONY "@APEX_WITH_ACTIVEHARMONY@")
set(ACTIVEHARMONY_ROOT "@ACTIVEHARMONY_ROOT@")
set(APEX_WITH_OTF2 "@APEX_WITH_OTF2@")
set(OTF2_ROOT "@OTF2_ROOT@")
include(HPX_SetupApex)
##################################################

set(HPX_WITH_MALLOC_DEFAULT @HPX_WITH_MALLOC@)

if(HPX_WITH_DATAPAR_VC AND NOT Vc_DIR)
  set(Vc_DIR "@Vc_DIR@")
endif()
include(HPX_SetupVc)

if(NOT HPX_CMAKE_LOGLEVEL)
  set(HPX_CMAKE_LOGLEVEL "WARN")
endif()

hpx_check_cmake_build_type()
hpx_check_compiler_compatibility()
hpx_check_boost_compatibility()
hpx_check_allocator_compatibility()

if(NOT DEFINED ${CMAKE_FIND_PACKAGE_NAME}_FOUND)
  set(${CMAKE_FIND_PACKAGE_NAME}_FOUND true)
endif()

# Set legacy variables for linking and include directories
set(HPX_LIBRARIES "HPX::hpx;")
# All properties are propagated from HPX::hpx, so the following can be empty
set(HPX_INCLUDE_DIRS "")
set(HPX_LIBRARY_DIR "")
set(HPX_LINK_LIBRARIES "")
set(HPX_LINKER_FLAGS "")
